<!-- 绿色通道 - 患者列表 - 医疗记录 - 基本信息(旧) 界面 -->
<template>
  <div class="info">
    <el-row type="flex" justify="end" style="padding-right: 40px">
      <el-button type="primary" @click="update">保存</el-button>
    </el-row>
    <el-form ref="patientForm" :model="patientForm" label-width="128px">
      <el-row class="form-row" type="flex">
        <el-form-item label="住院ID">
          <el-input v-model="patientForm.inpatientId" size="mini" />
        </el-form-item>
        <el-form-item label="门诊ID">
          <el-input v-model="patientForm.outpatientId" size="mini" />
        </el-form-item>
        <el-form-item label="发病时间" required>
          <el-date-picker
            v-model="patientForm.incidentDateTime"
            type="datetime"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <div v-if="false" class="equal-row-height">
          <el-checkbox v-model="patientForm.a">
            发病时间无法精确到分钟
          </el-checkbox>
        </div>
        <div v-if="false" class="equal-row-height not-accurate-minutes">
          <el-select v-model="patientForm.a1" size="mini" clearable>
            <el-option
              v-for="item in approximateTime"
              :key="'approximateTime' + item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </div>
      </el-row>
      <el-row class="form-row" type="flex">
        <el-form-item label="发病地址">
          <el-select
            v-model="patientForm.incidentProvince"
            size="mini"
            filterable
            clearable
            @change="provinceChange('incident')"
          >
            <el-option v-for="(area, index) in areaList" :key="'发病地址' + index" :value="area.name" />
          </el-select>
        </el-form-item>
        <div class="equal-row-height">
          <el-select v-model="patientForm.incidentCity" size="mini" clearable @change="cityChange('incident')">
            <el-option
              v-for="(city, index) in getCity('incidentProvince')"
              :key="'发病地址(市)' + index"
              :value="city.name"
            />
          </el-select>
        </div>
        <div class="equal-row-height">
          <el-select v-model="patientForm.incidentArea" size="mini" clearable>
            <el-option
              v-for="(city, index) in getArea(
                'incidentCity',
                'incidentProvince'
              )"
              :key="'发病地址(区)' + index"
              :value="city.name"
            />
          </el-select>
        </div>
        <div class="equal-row-height long-text">
          <el-input v-model="patientForm.incidentaddress" size="mini" placeholder="输入详细地址" />
        </div>
      </el-row>
      <el-row type="flex">
        <el-form-item v-if="false" label="来院时间">
          <el-date-picker v-model="patientForm.d" type="datetime" size="mini" value-format="yyyy-MM-dd HH:mm:ss" />
        </el-form-item>
        <el-form-item label="首诊医院">
          <el-input v-model="patientForm.hosName" size="mini" disabled />
        </el-form-item>
        <el-form-item label="首诊科室">
          <el-input v-model="patientForm.depName" size="mini" disabled />
        </el-form-item>
      </el-row>
      <el-row type="flex">
        <el-form-item label="患者姓名" required>
          <el-input v-model="patientForm.name" size="mini" />
        </el-form-item>
        <el-form-item label="性别" class="short-text" required>
          <el-select v-model="patientForm.sex" size="mini" clearable>
            <el-option value="男" />
            <el-option value="女" />
            <el-option value="未知" />
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" label-width="50px" class="short-text" required>
          <el-input v-model.number="patientForm.age" size="mini" />
        </el-form-item>
        <el-form-item label="身高" class="short-text">
          <el-input v-model="patientForm.height" size="mini" @input="BMI(patientForm.weight, patientForm.height)" />
        </el-form-item>
        <el-form-item label="体重" label-width="50px" class="short-text">
          <el-input v-model="patientForm.weight" size="mini" @input="BMI(patientForm.weight, patientForm.height)" />
        </el-form-item>
        <el-form-item label="BMI">
          <el-input v-model="patientForm.BMI" size="mini" />
        </el-form-item>
        <el-form-item label="出生日期">
          <el-date-picker
            v-model="patientForm.birthday"
            type="date"
            size="mini"
            value-format="yyyy-MM-dd"
            @change="patientForm.age = changeAge(patientForm.birthday)"
          />
        </el-form-item>
      </el-row>
      <el-row type="flex">
        <el-form-item label="证件类型" required>
          <el-select v-model="patientForm.credentialstype" size="mini" clearable>
            <el-option label="无" value="0" />
            <el-option label="身份证" value="1" />
            <el-option label="护照" value="2" />
            <el-option label="军官证" value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码">
          <el-input v-model="patientForm.idcardCopy" size="mini" @change="changeCard" />
        </el-form-item>
        <el-form-item label="国籍">
          <el-select v-model="patientForm.nationality" size="mini" clearable>
            <el-option value="中国" />
            <el-option value="外国" />
          </el-select>
        </el-form-item>
        <el-form-item label="民族">
          <el-select v-model="patientForm.ethnicity" size="mini" filterable clearable>
            <el-option v-for="(nation, index) in nationList" :key="'民族' + index" :value="nation.nationName" />
          </el-select>
        </el-form-item>
        <el-form-item label="婚姻状况">
          <el-select v-model="patientForm.maritalstatus" size="mini" clearable>
            <el-option value="未婚" />
            <el-option value="已婚" />
            <el-option value="离异" />
            <el-option value="丧偶" />
            <el-option value="未知" />
          </el-select>
        </el-form-item>
      </el-row>
      <el-row type="flex">
        <el-form-item label="医保类型">
          <el-select v-model="patientForm.medicalinsurancetype" size="mini" clearable>
            <el-option value="1" label="城镇职工基本医疗保险" />
            <el-option value="2" label="新型农村合作医疗" />
            <el-option value="3" label="城镇居民基本医疗保险" />
            <el-option value="4" label="自费" />
            <el-option value="5" label="军免" />
          </el-select>
        </el-form-item>
        <el-form-item label="医保账号">
          <el-input v-model="patientForm.medicalinsuranceno" size="mini" />
        </el-form-item>
        <el-form-item label="大病医保">
          <div class="radio-div">
            <el-radio v-model="patientForm.seriousDiseaseMedicalInsurance" label="1">
              是
            </el-radio>
            <el-radio v-model="patientForm.seriousDiseaseMedicalInsurance" label="0">
              否
            </el-radio>
          </div>
        </el-form-item>
        <el-form-item label="文化程度">
          <el-select v-model="patientForm.culturedegree" size="mini" clearable>
            <el-option value="01" label="没上过学" />
            <el-option value="02" label="小学" />
            <el-option value="03" label="初中" />
            <el-option value="04" label="高中或中专（中技）" />
            <el-option value="05" label="大专" />
            <el-option value="06" label="本科及以上" />
            <el-option value="09" label="不详" />
          </el-select>
        </el-form-item>
        <el-form-item label="职业">
          <el-select v-model="patientForm.job" size="mini" clearable>
            <el-option value="01" label="国家机关，党群组织，企事业单位负责人" />

            <el-option value="02" label="各类专业技术人员" />
            <el-option value="03" label="办事人员和有关人员" />
            <el-option value="04" label="商业及服务型工作人员" />
            <el-option value="05" label="农，林，牧，渔，水利业生产人员" />
            <el-option value="06" label="下岗或无业" />
            <el-option value="07" label="离退休" />
            <el-option value="08" label="学生" />
            <el-option value="09" label="均热" />
            <el-option value="10" label="不便分类的其他从业人员" />
          </el-select>
        </el-form-item>
      </el-row>
      <el-row type="flex" class="form-row">
        <el-form-item label="户籍所在地">
          <el-select v-model="patientForm.idProvince" size="mini" filterable clearable @change="provinceChange('id')">
            <el-option v-for="(area, index) in areaList" :key="'户籍所在地' + index" :value="area.name" />
          </el-select>
        </el-form-item>
        <div class="equal-row-height">
          <el-select v-model="patientForm.idCity" size="mini" clearable @change="cityChange('id')">
            <el-option v-for="(city, index) in getCity('idProvince')" :key="'户籍所在地(市)' + index" :value="city.name" />
          </el-select>
        </div>
        <div class="equal-row-height">
          <el-select v-model="patientForm.idArea" size="mini" clearable>
            <el-option
              v-for="(city, index) in getArea('idCity', 'idProvince')"
              :key="'户籍所在地(区)' + index"
              :value="city.name"
            />
          </el-select>
        </div>
        <div class="equal-row-height long-text">
          <el-input v-model="patientForm.idaddress" size="mini" placeholder="输入详细地址" />
        </div>
        <el-form-item label="联系电话">
          <el-input v-model="patientForm.contactphone" size="mini" />
        </el-form-item>
      </el-row>
      <el-row type="flex">
        <el-form-item label="来院方式" required>
          <div class="radio-div">
            <el-radio v-model="patientForm.comingWayCode" label="1">
              呼叫出车
            </el-radio>
            <el-radio v-model="patientForm.comingWayCode" label="2">
              转院
            </el-radio>
            <el-radio v-model="patientForm.comingWayCode" label="3">
              自行来院
            </el-radio>
            <el-radio v-model="patientForm.comingWayCode" label="4">
              院内发病
            </el-radio>
          </div>
        </el-form-item>
      </el-row>
      <el-row v-show="patientForm.comingWayCode == '1'">
        <el-row type="flex">
          <el-form-item label="出车单位" label-width="200px" required>
            <el-select v-model="patientForm.dispatchEmergens.ambulanceDepartment" size="mini">
              <el-option value="1" label="120救护车" />
              <el-option value="2" label="本院救护车" />
              <el-option value="3" label="外院救护车" />
            </el-select>
          </el-form-item>
          <el-form-item label="直接转送上级医院" label-width="200px" style="min-width: 420px" required>
            <el-radio v-model="patientForm.dispatchEmergens.isTransHospital" label="1">
              是
            </el-radio>
            <el-radio v-model="patientForm.dispatchEmergens.isTransHospital" label="0">
              否
            </el-radio>
          </el-form-item>
          <el-form-item
            v-if="patientForm.dispatchEmergens.isTransHospital && patientForm.dispatchEmergens.isTransHospital != '0'
            "
            label="直达导管室"
            label-width="200px"
            required
          >
            <el-radio v-model="patientForm.dispatchEmergens.isDirectConduitRoom" label="1">
              是
            </el-radio>
            <el-radio v-model="patientForm.dispatchEmergens.isDirectConduitRoom" label="0">
              否
            </el-radio>
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-form-item label="呼救时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.helpDate"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="首次医疗接触时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.firstMedicalContactDateTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-form-item label="首诊医生接诊时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.inhospitalAdmissionTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="到达本院大门时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.arrivalTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="医护人员" label-width="200px">
            <el-input v-model="patientForm.dispatchEmergens.cw120FirstDoctorName" size="mini" />
          </el-form-item>
        </el-row>
      </el-row>
      <el-row v-if="patientForm.comingWayCode == '2'">
        <el-row type="flex">
          <el-form-item label="转院类型" label-width="200px" required>
            <el-select v-model="patientForm.dispatchEmergens.cwZyTransType" size="mini">
              <el-option value="1" label="网络医院" />
              <el-option value="2" label="其他医疗机构" />
            </el-select>
          </el-form-item>
          <el-form-item label="医院名称" label-width="200px">
            <el-input
              v-if="patientForm.dispatchEmergens.cwZyTransType != 1"
              v-model="patientForm.dispatchEmergens.hospitalName"
              size="mini"
            />
            <el-select
              v-if="patientForm.dispatchEmergens.cwZyTransType == 1"
              v-model="patientForm.dispatchEmergens.hospitalName"
              size="mini"
            >
              <el-option v-for="(item, index) in netHosList" :key="index" :value="item.name" :label="item.name" />
            </el-select>
          </el-form-item>
          <el-form-item label="直接转送上级医院" label-width="200px" style="min-width: 420px" required>
            <el-radio v-model="patientForm.dispatchEmergens.isTransHospital" label="1">
              是
            </el-radio>
            <el-radio v-model="patientForm.dispatchEmergens.isTransHospital" label="0">
              否
            </el-radio>
          </el-form-item>
          <el-form-item
            v-if="patientForm.dispatchEmergens.isTransHospital &&
              patientForm.dispatchEmergens.isTransHospital != '0'
            "
            label="直达导管室"
            label-width="200px"
            required
          >
            <el-radio v-model="patientForm.dispatchEmergens.isDirectConduitRoom" label="1">
              是
            </el-radio>
            <el-radio v-model="patientForm.dispatchEmergens.isDirectConduitRoom" label="0">
              否
            </el-radio>
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-form-item label="首次医疗接触时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.firstMedicalContactDateTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
              required
            />
          </el-form-item>
          <el-form-item label="转出医院入门时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.outhospitalVisitTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="决定转院时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.transferTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="转出医院出门时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.leaveOuthospitalTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-form-item label="到达本院大门时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.arrivalTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="院内接诊时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.inhospitalAdmissionTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="医护人员" label-width="200px">
            <el-input v-model="patientForm.dispatchEmergens.cw120FirstDoctorName" size="mini" />
          </el-form-item>
        </el-row>
      </el-row>
      <el-row v-if="patientForm.comingWayCode == '3'">
        <el-row type="flex">
          <el-form-item label="到达本院大门时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.arrivalTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="首次医疗接触时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.firstMedicalContactDateTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="首诊医师接诊时间" label-width="200px" required>
            <el-date-picker
              v-model="patientForm.dispatchEmergens.inhospitalAdmissionTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="医护人员" label-width="200px">
            <el-input v-model="patientForm.dispatchEmergens.cw120FirstDoctorName" size="mini" />
          </el-form-item>
        </el-row>
      </el-row>
      <el-row v-if="patientForm.comingWayCode == '4'">
        <el-row>
          <el-row type="flex">
            <el-form-item label="发病科室" label-width="200px" required>
              <el-select v-model="patientForm.dispatchEmergens.attackDepartment" size="mini">
                <el-option v-for="(dept, index) in deptList" :key="'科室' + index" :value="dept.name" />
              </el-select>
            </el-form-item>
          </el-row>
          <el-row type="flex">
            <el-form-item label="首次医疗接触时间" label-width="200px" required>
              <el-date-picker
                v-model="patientForm.dispatchEmergens.firstMedicalContactDateTime
                "
                type="datetime"
                size="mini"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
            <el-form-item label="床位医生接触时间" label-width="200px">
              <el-date-picker
                v-model="patientForm.dispatchEmergens.cwYnfbConsultationTime"
                type="datetime"
                size="mini"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
            <el-form-item label="离开科室时间" label-width="200px">
              <el-date-picker
                v-model="patientForm.dispatchEmergens.leaveDepartmentTime"
                type="datetime"
                size="mini"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
            <el-form-item label="医护人员" label-width="200px">
              <el-input v-model="patientForm.dispatchEmergens.cw120FirstDoctorName" size="mini" />
            </el-form-item>
          </el-row>
        </el-row>
      </el-row>
      <div class="line" />
      <div style="margin-bottom: 10px;text-align: right;width: 98%;margin: 0px auto;">
        <el-button type="primary" size="small" @click="UploadImg(url)">上传图片</el-button>
      </div>
      <el-row v-if="url.length > 0" type="flex">
        <div v-for="(item, index) in url" :key="'图片' + index" class="outerBox">
          <i class="el-icon-error icon-style" @click="deleteImg(item)" />
          <el-image
            style="width: 100px; height: 100px; margin-left: 60px"
            :src="item"
            :preview-src-list="srcList"
            @click.stop="handleClick"
          />
        </div>
      </el-row>
      <el-row v-if="url.length == 0">
        <div
          style="
            width: 100px;
            height: 100px;
            margin-left: 60px;
            border: 1px solid #ddd;
            color: #ddd;
            display: flex;
            justify-content: center;
            align-items: center;
          "
        >
          无图片
        </div>
      </el-row>
      <div class="line" />
    </el-form>
    <!-- 上传图片弹窗 -->
    <el-dialog title="上传图片" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">
      <el-upload
        ref="date"
        action=""
        list-type="picture-card"
        :limit="10"
        :file-list="fileList"
        :auto-upload="false"
        :on-exceed="handleExceed"
        :on-change="uploadChange"
        :on-preview="handlePictureCardPreview"
        :on-remove="handleRemove"
      >
        <i class="el-icon-plus" />
      </el-upload>
      <el-dialog append-to-body width="50vh" top="50px" :visible.sync="dialogVisibleCard">
        <img width="100%" :src="dialogImageUrl" alt="">
      </el-dialog>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitUpload()">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  selectRegionEx,
  getPatientInfo,
  savePatientInfo,
  getPatientsImg,
  getDepartmentList,
  savePatientImg
} from '@/api/green-channel/info'
import { modifyMapData } from '@/api/green-channel/tab-request'

export default {
  name: 'Info',
  // 由主页面(父组件) 接收来的, 选择项的数据
  // eslint-disable-next-line vue/require-prop-types
  props: ['checkrowdata'], // 由主页面(父组件) 接收来的, 选择项的数据
  data() {
    return {
      netHosList: [],
      areaList: [],
      persondata: {},
      url: [],
      patientForm: {
        idcardCopy: '',
        comingWayCode: '',
        dispatchEmergens: {
          ambulanceDepartment: '',
          cwZyTransType: '',
          arrivalTime: '',
          attackDepartment: ''
        }
      },
      srcList: [],
      approximateTime: [
        { code: '1', name: '凌晨(0点到6点)' },
        { code: '2', name: '清晨(6到8点)' },
        { code: '3', name: '上午(8到12点)' },
        { code: '4', name: '中午(12到14点)' },
        { code: '5', name: '下午(14到17点)' },
        { code: '6', name: '傍晚(17到19点)' },
        { code: '7', name: '晚上(19到24点)' }
      ],
      nationList: [
        { nationCode: '01', nationName: '汉族' },
        { nationCode: '02', nationName: '蒙古族' },
        { nationCode: '03', nationName: '回族' },
        { nationCode: '04', nationName: '藏族' },
        { nationCode: '05', nationName: '维吾尔族' },
        { nationCode: '06', nationName: '苗族' },
        { nationCode: '07', nationName: '彝族' },
        { nationCode: '08', nationName: '壮族' },
        { nationCode: '09', nationName: '布依族' },
        { nationCode: '10', nationName: '朝鲜族' },
        { nationCode: '11', nationName: '满族' },
        { nationCode: '12', nationName: '侗族' },
        { nationCode: '13', nationName: '瑶族' },
        { nationCode: '14', nationName: '白族' },
        { nationCode: '15', nationName: '土家族' },
        { nationCode: '16', nationName: '哈尼族' },
        { nationCode: '17', nationName: '哈萨克族' },
        { nationCode: '18', nationName: '傣族' },
        { nationCode: '19', nationName: '黎族' },
        { nationCode: '20', nationName: '傈僳族' },
        { nationCode: '21', nationName: '佤族' },
        { nationCode: '22', nationName: '拉祜族' },
        { nationCode: '23', nationName: '高山族' },
        { nationCode: '24', nationName: '白族' },
        { nationCode: '25', nationName: '水族' },
        { nationCode: '26', nationName: '东乡族' },
        { nationCode: '27', nationName: '纳西族' },
        { nationCode: '28', nationName: '景颇族' },
        { nationCode: '29', nationName: '柯尔克孜族' },
        { nationCode: '30', nationName: '土族' },
        { nationCode: '31', nationName: '达斡尔族' },
        { nationCode: '32', nationName: '仫佬族' },
        { nationCode: '33', nationName: '羌族' },
        { nationCode: '34', nationName: '布朗族' },
        { nationCode: '35', nationName: '撒拉族' },
        { nationCode: '36', nationName: '毛南族' },
        { nationCode: '37', nationName: '仡佬族' },
        { nationCode: '38', nationName: '锡伯族' },
        { nationCode: '39', nationName: '阿昌族' },
        { nationCode: '40', nationName: '土族普米族' },
        { nationCode: '41', nationName: '塔吉克族' },
        { nationCode: '42', nationName: '怒族' },
        { nationCode: '43', nationName: '乌孜别克族' },
        { nationCode: '44', nationName: '俄罗斯族' },
        { nationCode: '45', nationName: '鄂温克族' },
        { nationCode: '46', nationName: '崩龙族' },
        { nationCode: '47', nationName: '保安族' },
        { nationCode: '48', nationName: '裕固族' },
        { nationCode: '49', nationName: '京族' },
        { nationCode: '50', nationName: '塔塔尔族' },
        { nationCode: '51', nationName: '独龙族' },
        { nationCode: '52', nationName: '鄂伦春族' },
        { nationCode: '53', nationName: '赫哲族' },
        { nationCode: '54', nationName: '门巴族' },
        { nationCode: '55', nationName: '珞巴族' },
        { nationCode: '56', nationName: '基诺族' },
        { nationCode: '97', nationName: '其他' },
        { nationCode: '98', nationName: '外国血统' }
      ],
      deptList: [],

      /* 上传图片  */
      dialogVisible: false,
      dialogVisibleCard: false,
      dialogImageUrl: '',
      fileList: []
    }
  },
  created() { },
  mounted() {
    this.getNetHos()
    this.getImg()
    this.getPatientInfo()
    this.selectRegionEx()
    this.getDepartmentList()
  },
  methods: {
    getNetHos() {
      this.netHosList = []
      modifyMapData({
        apiToken: this.$store.getters.apiToken,
        dispatchId: this.$store.getters.hospitalId,
        intf: 'get_nethospitals'
      }).then(res => {
        if (res.code == 0) {
          this.netHosList = res.data
        }
      })
    },
    changeCard(value) {
      if (this.patientForm.credentialstype == 1) {
        if (value) {
          this.patientForm.age = this.getAge(value)
          this.patientForm.sex = this.getSex(value)
        } else {
          this.patientForm.age = ''
          this.patientForm.sex = ''
        }
      }
    },
    getAge(idcard) {
      if (!idcard) {
        return ''
      }
      const len = (idcard + '').length
      let strBirthday = ''
      if (len == 18) {
        strBirthday = idcard.substr(6, 4) + '-' + idcard.substr(10, 2) + '-' + idcard.substr(12, 2)
      } else if (len == 15) {
        let birthdayValue = ''
        birthdayValue = idcard.charAt(6) + idcard.charAt(7)
        if (parseInt(birthdayValue) < 10) {
          strBirthday = '20' + idcard.substr(6, 2) + '-' + idcard.substr(8, 2) + '-' + idcard.substr(10, 2)
        } else {
          strBirthday = '19' + idcard.substr(6, 2) + '-' + idcard.substr(8, 2) + '-' + idcard.substr(10, 2)
        }
      } else {
        strBirthday = ''
      }
      if (strBirthday) {
        console.log('strBirthday', strBirthday)
        const birthDate = new Date(strBirthday)
        const nowDateTime = new Date()
        const temp_birthday = strBirthday.replace('/', '-')
        this.patientForm.birthday = temp_birthday
        let age = nowDateTime.getFullYear() - birthDate.getFullYear()
        if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
          age--
        }
        return age
      } else {
        return ''
      }
    },
    getSex(idcard) {
      if (!idcard) {
        return ''
      }
      const len = (idcard + '').length
      if (len == 18) {
        if (idcard.charAt(16) % 2 == 0) {
          return '女'
        } else {
          return '男'
        }
      } else if (len == 15) {
        if (idcard.charAt(14) % 2 == 0) {
          return '女'
        } else {
          return '男'
        }
      } else {
        return ''
      }
    },
    handleClick() {
      this.$nextTick(() => {
        const div = document.getElementsByClassName('el-image-viewer__actions__inner')
        const i = document.createElement('i')
        i.className = 'close-icon el-icon-close'
        document.querySelector('.el-image-viewer__close').style.display = 'none'
        div[0].appendChild(i)
        i.addEventListener('click', () => {
          document.querySelector('.el-image-viewer__close').click()
        })
      })
    },
    getDepartmentList() {
      getDepartmentList(this.$store.getters.hospitalId).then((res) => {
        this.deptList = res.data
      })
    },
    getImg() {
      getPatientsImg(this.checkrowdata.patientId).then((res) => {
        if (res.data) {
          this.srcList = res.data.split(',')
          this.url = res.data.split(',')
        }
      })
    },
    update() {
      console.log('this.patientForm1', this.patientForm)
      let tips = false
      if (!this.patientForm.incidentDateTime) {
        tips = '发病时间必须填写!'
      }
      //  else if (!this.patientForm.incidentProvince) {
      //   tips = '发病地址必须填写!'
      // } else if (!this.patientForm.incidentCity) {
      //   tips = '发病地址必须填写!'
      // } else if (!this.patientForm.incidentArea) {
      //   tips = '发病地址必须填写!'
      // }
      //  else if (!this.patientForm.incidentaddress) {
      //   tips = '发病详细地址必须填写!'
      // }
      else if (!this.patientForm.name) {
        tips = '姓名必须填写!'
      } else if (!this.patientForm.sex) {
        tips = '性别必须填写!'
      } else if (!this.patientForm.age) {
        tips = '年龄必须填写!'
      } else if (!this.patientForm.credentialstype) {
        tips = '证件类型必须填写!'
      } else if (this.patientForm.credentialstype !== '0' && !this.patientForm.idcardCopy) {
        tips = '证件号码必须填写!'
      } else if (!this.patientForm.comingWayCode) {
        tips = '来院方式必须选择!'
      } else if (!this.patientForm.comingWayCode) {
        tips = '来院方式必须选择!'
      } else if (!this.patientForm.dispatchEmergens.firstMedicalContactDateTime) {
        tips = '首次医疗接触时间必须选择!'
      } else if (this.patientForm.comingWayCode == '1' || this.patientForm.comingWayCode == '2' || this.patientForm.comingWayCode == '3') {
        if (!this.patientForm.dispatchEmergens.arrivalTime) {
          tips = '到达本院大门时间必须填写!'
        }
      }
      // let temp_age
      // let now_data = new Date()
      // if(this.patientForm.birthday){
      //   temp_age = new Date(this.patientForm.birthday.replace(/\//g,"-"))
      //   if(now_data.getFullYear()-temp_age.getFullYear()<Number(this.patientForm.age) || (now_data.getFullYear()-temp_age.getFullYear()===Number(this.patientForm.age) && (now_data.getMonth()<temp_age.getMonth() || (now_data.getMonth()===temp_age.getMonth() && now_data.getDate()<temp_age.getDate())))){
      //     tips = '出生日期到现在的年份小于当前年龄!'
      //     console.log(temp_age)
      //     return
      //   }
      // }

      // console.log(temp_age)
      // console.log(now_data.getFullYear()-temp_age.getFullYear()===Number(this.patientForm.age) && (now_data.getMonth()<temp_age.getMonth()))
      console.log('this.patientForm2', this.patientForm)
      if (this.patientForm.credentialstype === '0') {
        this.patientForm.idcardid = ''
        this.patientForm.idcardCopy = ''
        this.patientForm.birthday = ''
      }

      if (tips) {
        this.$message.warning(tips)
        return
      }

      this.patientForm.patientId = this.checkrowdata.patientId
      this.patientForm.dispatchId = this.checkrowdata.dispatchId
      if (this.patientForm.credentialstype !== '0' && this.patientForm.idcardCopy) {
        if (this.patientForm.idcardCopy.indexOf('*') == -1) {
          this.patientForm.idcardid = this.patientForm.idcardCopy
        }
      }
      savePatientInfo(this.patientForm).then((res) => {
        this.$message.success('保存成功')
        this.getPatientInfo()
      })
    },
    selectRegionEx() {
      selectRegionEx().then((res) => {
        this.areaList = res.data
      })
    },
    BMI(weight, height) {
      let num = 0
      if (weight && height) {
        num = weight / ((height * height) / 10000)
      }
      if (num === 0) {
        this.patientForm.BMI = null
      } else {
        this.patientForm.BMI = num.toFixed(2)
      }
    },
    provinceChange(field) {
      this.$set(this.patientForm, field + 'City', '')
      this.$set(this.patientForm, field + 'Area', '')
    },
    cityChange(field) {
      this.$set(this.patientForm, field + 'Area', '')
    },
    getCity(field) {
      let city = []
      let arr = []
      if (this.patientForm[field]) {
        city = this.areaList.filter(
          (item) => item.name === this.patientForm[field]
        )

        if (city.length > 0) {
          arr = city[0].cityList
        }
      }
      return arr
    },
    getArea(field, provinceField) {
      let area = []
      let arr = []
      if (this.getCity(provinceField).length > 0 && this.patientForm[field]) {
        area = this.getCity(provinceField).filter(
          (item) => item.name === this.patientForm[field]
        )
        if (area.length > 0) {
          arr = area[0].areaList
        }
      }
      return arr
    },
    getPatientInfo() {
      getPatientInfo(
        this.checkrowdata.patientId,
        this.checkrowdata.dispatchId
      ).then((res) => {
        if (res) {
          console.log(res, 'res')
          this.patientForm = res
          if (res.dispatchEmergens) {
            this.patientForm.dispatchEmergens = res.dispatchEmergens ? res.dispatchEmergens : {}
            this.patientForm.dispatchEmergens.ambulanceDepartment = res.dispatchEmergens.ambulanceDepartment ? res.dispatchEmergens.ambulanceDepartment : ''
            this.patientForm.dispatchEmergens.cwZyTransType = res.dispatchEmergens.cwZyTransType ? res.dispatchEmergens.cwZyTransType : ''
            this.patientForm.dispatchEmergens.arrivalTime = res.dispatchEmergens.arrivalTime ? res.dispatchEmergens.arrivalTime : ''
            this.patientForm.dispatchEmergens.attackDepartment = res.dispatchEmergens.attackDepartment ? res.dispatchEmergens.attackDepartment : ''
          } else {
            this.$set(this.patientForm, 'dispatchEmergens', {})
            this.$set(this.patientForm.dispatchEmergens, 'ambulanceDepartment', '')
            this.$set(this.patientForm.dispatchEmergens, 'cwZyTransType', '')
            this.$set(this.patientForm.dispatchEmergens, 'arrivalTime', '')
            this.$set(this.patientForm.dispatchEmergens, 'attackDepartment', '')

            // this.patientForm.dispatchEmergens = {}
            // this.patientForm.dispatchEmergens.ambulanceDepartment = ''
            // this.patientForm.dispatchEmergens.cwZyTransType = ''
            // this.patientForm.dispatchEmergens.arrivalTime = ''
            // this.patientForm.dispatchEmergens.attackDepartment = ''
          }
          if (this.patientForm.birthday) {
            this.patientForm.birthday = this.patientForm.birthday.replace(/\//, '-')
          }
          this.patientForm.comingWayCode = res.comingWayCode ? res.comingWayCode : ''
          if (res.idcardid) {
            this.$set(this.patientForm, 'idcardCopy', res.idcardid.replace(/^(.{6})(?:\w+)(.{4})$/, '\$1******\$2'))
          }
          if (res.credentialstype == 1 && (res.idcardid && res.idcardid.length === 18)) {
            this.patientForm.age = this.getAge(res.idcardid)
            this.patientForm.sex = this.getSex(res.idcardid)
          }

          this.BMI(this.patientForm.weight, this.patientForm.height)
        }
      })
    },
    /* 上传图片 --------- */
    UploadImg(url) {
      const urlList = url.map((item) => {
        return {
          name: item,
          url: item
        }
      })
      this.fileList = urlList
      this.dialogVisible = true
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
          this.fileList = []
        })
        .catch(_ => { })
    },
    cancel() {
      this.dialogVisible = false
      this.fileList = []
    },
    handleExceed(files, fileList) {
      this.$message.warning(`最多可上传十张照片`)
    },
    uploadChange(file, fileList) {
      this.fileList = fileList
    },
    handleRemove(file, fileList) {
      this.fileList = fileList
      console.log(file, fileList)
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisibleCard = true
    },
    // 删除照片
    deleteImg(item) {
      this.$confirm('确认删除本张图片？')
        .then(_ => {
          if (this.url.includes(item)) {
            this.url.splice(item, 1)
            console.log('url', this.url)
          }
          const formData = new FormData()
          const imageUrl = this.url.join(',')
          formData.set('imageUrl', imageUrl)
          formData.append('patientId', this.checkrowdata.patientId)
          savePatientImg(formData).then((res) => {
            console.log(res)
            if (res.code === 0) {
              this.$message.success('删除成功')
              this.dialogVisible = false
              this.fileList = []
              this.getImg()
            }
          }).catch(() => {
            this.$message.error('删除失败')
          })
          // done()
        })
        .catch(_ => { })
    },
    // 保存
    submitUpload() {
      const formData = new FormData()
      const imageUrlArr = []
      let imageUrl = ''
      formData.append('patientId', this.checkrowdata.patientId)
      this.fileList.forEach((item, key) => {
        if (item.status === 'success') {
          imageUrlArr.push(item.url)
          imageUrl = imageUrlArr.join(',')
          formData.set('imageUrl', imageUrl)
        } else {
          formData.append('image' + (key + 1), item.raw)
        }
      })
      savePatientImg(formData).then((res) => {
        console.log(res)
        if (res.code === 0) {
          this.$message.success('保存成功')
          this.dialogVisible = false
          this.fileList = []
          this.getImg()
        }
      }).catch(() => {
        this.$message.error('保存失败')
      })
    },
    changeAge(birthday) {
      if (birthday) {
        const temp_age = new Date(birthday)
        const now_time = new Date()
        let age
        if (now_time.getMonth() - temp_age.getMonth() > 0 || (now_time.getMonth() - temp_age.getMonth() === 0 && now_time.getDate() - temp_age.getDate() >= 0)) {
          age = now_time.getFullYear() - temp_age.getFullYear()
        } else if (now_time.getMonth() - temp_age.getMonth() === 0 && now_time.getDate() - temp_age.getDate() < 0) {
          age = now_time.getFullYear() - temp_age.getFullYear() - 1
        } else if (now_time.getMonth() - temp_age.getMonth() < 0) {
          age = now_time.getFullYear() - temp_age.getFullYear() - 1
        }

        // if ((now_time.getMonth() + 1) >= Number(temp_birthday_arr[1]) && now_time.getDate() >= Number(temp_birthday_arr[2])) {
        //   age += 1
        // }
        return age
      } else {
        return ''
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.info {
  overflow-x: auto;
  min-height: 80vh;

  .equal-row-height {
    line-height: 36px;
  }

  .form-row {
    .equal-row-height {
      margin-left: 20px;
    }
  }

  .el-form-item {
    margin-bottom: 10px;
  }

  .line {
    height: 1px;
    width: 100%;
    border-top: 1px dashed #dcdfe6;
    margin: 10px 0 20px 0;
  }

  .outerBox {
    position: relative;
  }

  .icon-style {
    position: absolute;
    top: 0px;
    right: 0px;
    z-index: 99;
    font-size: 20px;
    font-weight: 700;
  }

  .icon-style:hover {
    cursor: pointer;
  }
}
</style>
<style lang="scss">
.info {
  .el-form-item__label {
    font-weight: normal;
  }

  .not-accurate-minutes {
    .el-input__inner {
      width: 130px;
      min-width: unset;
    }
  }

  .short-text {
    .el-input__inner {
      width: 85px;
      min-width: unset;
    }
  }

  .el-input__inner {
    min-width: 220px;
  }

  .radio-div {
    min-width: 220px;
  }

  .long-text {
    .el-input__inner {
      min-width: 545px;
    }
  }
}
</style>

<style scoped>
.table-bordered {
  border: 1px solid #ddd;
}

.table {
  width: 100%;
  max-width: 100%;
  margin-bottom: 20px;
}

th,
td {
  padding: 5px;
  border: 1px solid #ddd;
}

th {
  width: 200px;
}

td {
  width: 500px;
}

label.red-star::before{
  content:"*";
  color: red;
}
</style>
